package at.fhooe.engine.event.events;

import at.fhooe.engine.event.EventListener;
import at.fhooe.engine.pandora.Game;

public class CollisionEvent extends Event {
	
	public static final String TYPE = "CollisionEvent";
	
	private String m_nameEntity1;
	private String m_nameEntity2;

	public CollisionEvent(String nameEntity1, String nameEntity2) {
		super(TYPE);
		m_nameEntity1 = nameEntity1;
		m_nameEntity2 = nameEntity2;
	}
	
	public void processEvent(EventListener eventListener) {
		((Listener) eventListener).onCollisionEvent(this);
	}
	
	public String getNameEntity1() {
		return m_nameEntity1;
	}

	public void setNameEntity1(String nameEntity1) {
		this.m_nameEntity1 = nameEntity1;
	}

	public String getNameEntity2() {
		return m_nameEntity2;
	}

	public void setNameEntity2(String nameEntity2) {
		this.m_nameEntity2 = nameEntity2;
	}
	
	public boolean isEntityInvolved(String entityName) {
		if(m_nameEntity1.equalsIgnoreCase(entityName) || m_nameEntity2.equalsIgnoreCase(entityName)) {
			return true;
		}
		return false;
	}
	
	public Object getOpponent(String entityName) {
		if (m_nameEntity1.equalsIgnoreCase(entityName)) {
			Object o;
			o = Game.getInstance().getEntityManager().getEntity(m_nameEntity2);
			if(o == null) {
				o = Game.getInstance().getPathfindingManager().getMapObject(m_nameEntity2);
			}
			return o;
		} else if (m_nameEntity2.equalsIgnoreCase(entityName)) {
			Object o;
			o = Game.getInstance().getEntityManager().getEntity(m_nameEntity1);
			if(o == null) {
				o = Game.getInstance().getPathfindingManager().getMapObject(m_nameEntity1);
			}
			return o;
		}
		return null;
	}

	//embedded listener interface with the specific function call
	public interface Listener extends EventListener {
		public void onCollisionEvent(CollisionEvent collisionEvent);
	}

}
